#include "Avatar.h"
#include <SFML\Graphics.hpp>

Avatar::Avatar(Vector2f dimension, Color color, Vector2f velocity, Vector2f position, AnimationHandlerFactory* animationHandlerFactory) : 
	Movable(dimension,color,velocity,position, animationHandlerFactory),
	_nb_life(2), _nb_heart(3), _nb_gold(0)
{
	_animationHandlerFactory->getAnimationHandler(avatar)->attachTexture(this);
}

Avatar::~Avatar() {}


void Avatar::draw(RenderWindow& window) const
{
	window.draw(_shape);
}

int Avatar::lose_heart()
{
	setInvicibilityDelay(1000); //cannot suffer new damage for the next 1000ms
	_nb_heart--;

	return _nb_heart;
}

int Avatar::loseLife()
{	
		_nb_heart=3;
		_nb_life--;

	return _nb_life;
}

bool Avatar::isDead()
{
	return _nb_life<0;
}
void Avatar::updateAnimation()
{
	_animationHandlerFactory->getAnimationHandler(avatar)->updateMovable(this);
}

void Avatar::setInvicibilityDelay(int ms)
{
	_invicibilityChronometer.setTimer(ms);
}
bool Avatar::isInvicible()
{
	return !_invicibilityChronometer.isDelayElapsed();
}